/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ejb.entities;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author simone
 */
@Entity
@Table(name = "Viaggio")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Viaggio.findAll", query = "SELECT v FROM Viaggio v"),
    @NamedQuery(name = "Viaggio.findByIdViaggio", query = "SELECT v FROM Viaggio v WHERE v.idViaggio = :idViaggio"),
    @NamedQuery(name = "Viaggio.findByCost", query = "SELECT v FROM Viaggio v WHERE v.cost = :cost")})
public class Viaggio implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id_viaggio")
    private Integer idViaggio;
    @Basic(optional = false)
    @NotNull
    @Column(name = "cost")
    private double cost;
    @OneToMany(mappedBy = "fkViaggio")
    private Collection<Pacchettoprenotato> pacchettoprenotatoCollection;
    @JoinColumn(name = "fk_tipo_viaggio", referencedColumnName = "id_tipo_viaggio")
    @ManyToOne(optional = false)
    private Tipoviaggio fkTipoViaggio;
    @JoinColumn(name = "fk_partenza", referencedColumnName = "id_citta")
    @ManyToOne(optional = false)
    private Citta fkPartenza;
    @JoinColumn(name = "fk_arrivo", referencedColumnName = "id_citta")
    @ManyToOne(optional = false)
    private Citta fkArrivo;

              
    @ManyToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "Comprende_prodotti",
            joinColumns = {@JoinColumn(name = "id_viaggio", referencedColumnName = "id_viaggio")},
            inverseJoinColumns = {@JoinColumn(name = "id_pacchetto", referencedColumnName = "id_pacchetto")})
    private List<Pacchetto>pacchettiOwnTravels;


    
    
    
    public Viaggio() {
    }

    public Viaggio(Integer idViaggio) {
        this.idViaggio = idViaggio;
    }

    public Viaggio(Integer idViaggio, double cost) {
        this.idViaggio = idViaggio;
        this.cost = cost;
    }

    public List<Pacchetto> getPacchettiOwnTravels() {
        return pacchettiOwnTravels;
    }

    
    
    public Integer getIdViaggio() {
        return idViaggio;
    }

    public void setIdViaggio(Integer idViaggio) {
        this.idViaggio = idViaggio;
    }

    public double getCost() {
        return cost;
    }

    public void setCost(double cost) {
        this.cost = cost;
    }

    @XmlTransient
    public Collection<Pacchettoprenotato> getPacchettoprenotatoCollection() {
        return pacchettoprenotatoCollection;
    }

    public void setPacchettoprenotatoCollection(Collection<Pacchettoprenotato> pacchettoprenotatoCollection) {
        this.pacchettoprenotatoCollection = pacchettoprenotatoCollection;
    }

    public Tipoviaggio getFkTipoViaggio() {
        return fkTipoViaggio;
    }

    public void setFkTipoViaggio(Tipoviaggio fkTipoViaggio) {
        this.fkTipoViaggio = fkTipoViaggio;
    }

    public Citta getFkPartenza() {
        return fkPartenza;
    }

    public void setFkPartenza(Citta fkPartenza) {
        this.fkPartenza = fkPartenza;
    }

    public Citta getFkArrivo() {
        return fkArrivo;
    }

    public void setFkArrivo(Citta fkArrivo) {
        this.fkArrivo = fkArrivo;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idViaggio != null ? idViaggio.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Viaggio)) {
            return false;
        }
        Viaggio other = (Viaggio) object;
        if ((this.idViaggio == null && other.idViaggio != null) || (this.idViaggio != null && !this.idViaggio.equals(other.idViaggio))) {
            return false;
        }
        return true;
    }

    public String infoTrip()
    {
        String info;
        info  = fkTipoViaggio.getName()+": "+fkPartenza.getCity()+" - "+fkArrivo.getCity();
        return info;
    }
    
}
